package com.jscm.openselect;

import com.scm.all.export.ByteUtils;
import com.scm.all.export.SystemUtils;
import com.scm.all.export.WindowOperationUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.CheckBox;
import org.apache.commons.lang3.StringUtils;

/**
 * 转十六进制
 */
public class SelectOptionCheckBoxHex {
    public static CheckBox checkBox = new CheckBox();
    static {
        init();
    }

    private static void init() {

        checkBox.setText("指针转HEX");
        checkBox.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if(!StringUtils.equals(SelectText.textField.getText(),"")){
                    try {
                        if(checkBox.isSelected()){
                            SelectText.textField.setText(ByteUtils.longToByteHex(Long.parseLong(SelectText.textField.getText())));
                        }else {
                            SelectText.textField.setText(""+ByteUtils.hexToLong2(SelectText.textField.getText()));
                        }
                    }catch (NumberFormatException numberFormatException){
                        SystemUtils.messageBoxExW(WindowOperationUtils.windowGetHwnd(),"指针不存在小数类型/或其它类型问题","温馨提示",0);
                        checkBox.setSelected(false);
                    }

                }else {
                    SystemUtils.messageBoxExW(WindowOperationUtils.windowGetHwnd(),"指针不能为空","温馨提示",0);
                    checkBox.setSelected(false);
                }

            }
        });
    }
}
